<?php

namespace App\Exceptions;

use App\Error\BaseError;
use Composer\Package\Loader\ValidatingArrayLoader;
use Exception;
use Illuminate\Http\Exceptions\HttpResponseException;
use Symfony\Component\HttpFoundation\Response;

class KfHttpResponseException extends HttpResponseException
{
    /**
     * @param array $error
     * @param int $httpStatusCode
     * @param array $headers
     * @throws Exception
     */
    public function __construct(array $error, int $httpStatusCode = Response::HTTP_OK, array $headers = [])
    {
        try {
            parent::__construct(response()->json([
                "code" => $error["code"],
                "msg"  => $error["cn"],
                "data" => null
            ], $httpStatusCode, $headers));
        } catch (Exception $exception) {
            handleKfException($exception, BaseError::SERVER_INTERNAL_ERROR, func_get_args());
        }
    }
}
